﻿#region File Description
//-----------------------------------------------------------------------------
// InputState.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
#endregion

namespace DungDungShit
{
    /// <summary>
    /// Helper for reading input from keyboard, gamepad, and touch input. This class 
    /// tracks both the current and previous state of the input devices, and implements 
    /// query methods for high level input actions such as "move up through the menu"
    /// or "pause the game".
    /// </summary>
    public class InputState
    {
        #region Fields

        private KeyboardState currentKeyboardState;
        private MouseState currentMouseState;

        private KeyboardState lastKeyboardState;
        private MouseState lastMouseState;

        #endregion

        #region Properties

        public KeyboardState CurrentKeyboardState { get { return currentKeyboardState; } }
        public MouseState CurrentMouseState { get { return currentMouseState; } }

        public KeyboardState LastKeyboardState { get { return lastKeyboardState; } }
        public MouseState LastMouseState { get { return lastMouseState; } }

        #endregion

        #region Initialization


        /// <summary>
        /// Constructs a new input state.
        /// </summary>
        public InputState() { }

        #endregion

        #region Public Methods


        /// <summary>
        /// Reads the latest state of the keyboard and gamepad.
        /// </summary>
        public void Update()
        {
            lastKeyboardState = currentKeyboardState;
            lastMouseState = currentMouseState;
            currentKeyboardState = Keyboard.GetState();
            currentMouseState = Mouse.GetState();
        }


        public bool IsNewKeyPress(Keys key)
        {
            return (currentKeyboardState.IsKeyDown(key) && lastKeyboardState.IsKeyUp(key));
        }

        public bool IsMenuSelect()
        {
            return (IsNewKeyPress(Keys.Space) || IsNewKeyPress(Keys.Enter));
        }

        public bool IsMenuCancel()
        {
            return IsNewKeyPress(Keys.Escape);
        }

        public bool IsMenuUp()
        {
            return IsNewKeyPress(Keys.Up);
        }

        public bool IsMenuDown()
        {
            return IsNewKeyPress(Keys.Down);
        }

        public bool IsMenuUpHold()
        {
            return currentKeyboardState.IsKeyDown(Keys.Up);
        }

        public bool IsMenuDownHold()
        {
            return currentKeyboardState.IsKeyDown(Keys.Down);
        }

        public bool IsPauseGame()
        {
            return IsNewKeyPress(Keys.Escape);
        }


        #endregion
    }
}
